package com.alex.common.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.alex.common.security.SimpleAuthor;

public class UserInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		if (exclude_mapping != null) {
			String uri = request.getRequestURI();
			for (String exclude : exclude_mapping) {
				if (exclude.equalsIgnoreCase(uri)) {
					return true;
				}
			}
		}
		return SimpleAuthor.getInstance().needUser(request, response);
	}

	private List<String> exclude_mapping;

	public List<String> getExclude_mapping() {
		return exclude_mapping;
	}

	public void setExclude_mapping(List<String> exclude_mapping) {
		this.exclude_mapping = exclude_mapping;
	}

}
